package behavior.interpreter;

import java.math.BigDecimal;

public class NonTerminalExpression extends AbstractExpression{

    private AbstractExpression preExpression;
    private String symbol;
    private AbstractExpression postExpression;
    public NonTerminalExpression(AbstractExpression pre, AbstractExpression post, String _symbol){
        preExpression = pre;
        postExpression = post;
        symbol = _symbol;
    }

    @Override
    public BigDecimal interpreter(ParseContext context){
        switch(symbol){
            case "+":
                return preExpression.interpreter(context).add(postExpression.interpreter(context));
            case "-":
                return preExpression.interpreter(context).subtract(postExpression.interpreter(context));
            case "*":
                return preExpression.interpreter(context).multiply(postExpression.interpreter(context));
            case "/":
                return preExpression.interpreter(context).divide(postExpression.interpreter(context));
        }
        throw new UnsupportedOperationException("current symbol not supported : ["+ symbol +"]");

    }
}
